<!--  -->
<template>
  <div class="homeMarket">
    <div class="header">
      <van-icon name="arrow-left" size="18" @click="goBack()" />
      <p>楼市圈</p>
      <span></span>
    </div>
    <div class="content">
      <dl v-for="(item, idx) in list" :key="idx" class="list">
        <dt>
          <img :src="item.imgInfo" alt="" />
          {{ item.name }}
        </dt>
        <dd>
          <p>
            <span>{{ item.time }}</span>
            <span>{{ item.title }}</span>
          </p>
          <p>
            <span>4-28</span>
            <img :src="item.img" alt="" />
          </p>
          <p @click="handleDelete(item.id)">删除</p>
        </dd>
      </dl>
    </div>
  </div>
</template>

<script>
import { gethomeMarket, getMarketDetete } from "@/api";
export default {
  // 组件状态值
  data() {
    return {
      list: [],
    };
  },
  // 计算属性
  computed: {},
  // 组件方法
  methods: {
    //返回上一级
    goBack() {
      this.$router.push("/");
    },
    //获取数据
    getList() {
      gethomeMarket().then((res) => {
        console.log(res);
        this.list = res.data.data;
      });
    },
    //删除
    handleDelete(id) {
      getMarketDetete({ id }).then((res) => {
        console.log(res);
        this.getList();
      });
    },
  },
  /**
   * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
   */
  created() {
    this.getList();
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<!--使用了scoped属性之后，父组件的style样式将不会渗透到子组件中，-->
<!--然而子组件的根节点元素会同时被设置了scoped的父css样式和设置了scoped的子css样式影响，-->
<!--这么设计的目的是父组件可以对子组件根元素进行布局。-->
<style lang="scss" scoped>
.homeMarket {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.header {
  width: 100%;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 18px;
  color: #fff;
  background: #4381e6;
  padding: 0 15px;
}
.content {
  flex: 1;
  overflow: auto;
}
.list {
  width: 100%;
  padding-left: 10px;
  margin: 20px 0;
  dt {
    display: flex;
    align-items: center;
    img {
      width: 40px;
      border-radius: 50%;
    }
  }
  dd {
    padding-left: 10px;
    p:nth-child(1) {
      display: flex;
      margin: 10px 0;
      span {
        margin: 0 10px;
      }
    }
    p:nth-child(2) {
      display: flex;
      padding-left: 10px;
      span:nth-child(1) {
        color: #ccc;
      }
      img {
        width: 60%;
        height: 120px;
        margin-left: 13px;
      }
    }
    p:nth-child(3) {
      width: 100%;
      text-align: center;
      margin-top: 20px;
    }
  }
}
</style>
